package com.put.mybills.adapter;



import java.util.List;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.put.mybills.activities.FactureAnticipationFragment;
import com.put.mybills.activities.FactureSettings;
import com.put.mybills.activities.GraphFragment;
import com.put.mybills.activities.SummaryFragment;
import com.put.mybills.model.Facture;
import com.put.mybills.model.Unit;



public class TabSwipeFacture extends FragmentPagerAdapter  {
	
	private String factureName;
	private Boolean ifAddUnits = false;
	
	public TabSwipeFacture(FragmentManager fm, String factureName) {		
        super(fm);
        this.factureName = factureName;
        
    }
	
	

	@Override
    public Fragment getItem(int index) {
		
		
		if (ifAddUnits == true){
 
	        switch (index) {
	        case 0: 
	        	 return new GraphFragment(factureName);    
	        case 1:           
	        	return new SummaryFragment(factureName);
	        case 2:
	        	return new FactureSettings(factureName);
	        case 3:
	        	return new FactureAnticipationFragment(factureName); 
	        }       
		}
		else {
			
		   switch (index) {
	        case 0: 
	        	 return new GraphFragment(factureName);    
	        case 1:           
	        	return new SummaryFragment(factureName);
	        case 2:
	        	return new FactureSettings(factureName); 
	        }			
		}
        return null;
    }
 
    @Override
    public int getCount() {
    	if (ifAddUnits == true){
    		 return 4;
    	}
    	else
    	{
    		return 3;    	
    	}
       
    }

	public String getFactureName() {
		return factureName;
	}

	public void setFactureName(String factureName) {
		this.factureName = factureName;		
		Facture facture = GlobalParams.getInstance().facturedatasource.getFacture(factureName);		
		List<Unit> units = GlobalParams.getInstance().unitdatasource.getAllUnitForFacture(facture.getId());
		
		if (units.size()>0)
			ifAddUnits = true;
		
		
	}

}
